package com.tz.entity;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

@Entity
@Table(name = "SHOPPING_PRODUCT")
public class Product implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = 2975045224949360527L;
    //商品id
    private long id;
    //商品�
    private String name;
    //商品附属标签
    private String subName;
    //价格
    private double price;
    //折扣
    private double discount;
    //�?
    private double tax;
    //商品描述
    private String description;
    //图片集合
    private List<Picture> pictures;
    //库存
    private int stock;
    //商品细节
    private String detail;
    //商品颜色
    private String color;
    //商品分类
    private Category category;

    public Product() {

    }

    public Product(String name, double price, String color) {
        this.name = name;
        this.price = price;
        this.color = color;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "product_id")
    @SequenceGenerator(name = "product_id", sequenceName = "shop_product_id")
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSubName() {
        return subName;
    }

    public void setSubName(String subName) {
        this.subName = subName;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public double getDiscount() {
        return discount;
    }

    public void setDiscount(double discount) {
        this.discount = discount;
    }

    public double getTax() {
        return tax;
    }

    public void setTax(double tax) {
        this.tax = tax;
    }

        @Column(length = 1024)
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @OneToMany(fetch = FetchType.EAGER)
    @JoinColumn(name = "product_id")
    public List<Picture> getPictures() {
        return pictures;
    }

    public void setPictures(List<Picture> pictures) {
        this.pictures = pictures;
    }

    public int getStock() {
        return stock;
    }

    public void setStock(int stock) {
        this.stock = stock;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    @ManyToOne
    @JoinColumn(name = "category_id")
    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }


    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("Product{");
        sb.append("id=").append(id);
        sb.append(", name='").append(name).append('\'');
        sb.append(", subName='").append(subName).append('\'');
        sb.append(", price=").append(price);
        sb.append(", discount=").append(discount);
        sb.append(", tax=").append(tax);
        sb.append(", description='").append(description).append('\'');

        sb.append(", stock=").append(stock);
        sb.append(", detail='").append(detail).append('\'');
        sb.append(", color='").append(color).append('\'');

        sb.append('}');
        return sb.toString();
    }
}
